// 卢老爷极限解析
// 武器推荐  狼末/无工 > 骨剑
// 90级面板
// 白值:234, 暴击率:5, 暴击伤害:50, 物理伤害加成: 30

// 圣遗物选择魔女4  
// 初始副词条取最优 攻精通双暴 精通攻双暴 精通攻双暴 精通攻双暴 精通攻攻爆  // 副词条效果与主词条效果不重复 每个圣遗物5次强化副词条全排列取最优结果 


// 输出手法 行秋上水q 卢老爷 qaaeaaeaaeaa aaaa aaaa e   // 需要高命保证后续普攻打两套 不然只能打一套多
// q第一段 三段e 后续普攻中的几段可以吃到蒸发

// 骨剑 510面板 27.6%暴击   50增伤(满层)
// 圣遗物 攻击 火 暴伤    副词条强化搭配  攻击力:40.6（7） 暴击率:27.3(7)  暴击伤害:85.8(11)
// 数值 攻击力 2107  暴击98.6  爆伤229.2
// 总 53344

// 狼末跟无工 608面板 49.6攻击 40攻击 // 额外特效无工40攻击  狼末80攻击
// 圣遗物 攻击 火 暴击    副词条强化搭配  暴击率:27.3(7)  暴击伤害:140.4(18) 
// 数值 攻击力 2776  暴击98.2  爆伤229.4
// 总 571008    无工全程带盾 648592    狼末全程buff 726176



let charaters = {
    leize : {
        name: "lv90卢", 
        base: 335,
        attRate: 80,
        criticalRate: 24.2,
        criticalStrike: 50
    }
}

let weapons = {
    wugong: {
        name:"lv90无工之剑",
        base: 608,
        attRate: 49.6 + 40  // 有护盾额外加40
    },
    tkDj: {
        name:"lv90天空之傲", // q后普攻8次攻击力x1.6 真空刃
        dmgRate: 16,
        base: 674,
        充能: 36.8
    },
    langmo: { 
        name:"lv90狼末",
        base: 608,
        attRate: 49.6 + 40   // 触发buff 额外加80
    },
    gh: {
        name:"lv90古华",  // 15s 一次 攻击力x4.8 伤害
        base: 565,
        attRate: 27.6
    },
    sz: {
        name:"lv90霜葬",  // 10s 一次 1.4/3.6(敌人被冰附着) * 1.5(15s输出率) 
        base: 565,
        dmgRate: 34.5
    },
    cg:{
        name:"lv90骨剑",
        base: 510,
        criticalRate: 27.6,
        dmgRate:50
    },
}
let normal_clips = calc_clips_normal();
let normal_clips2 = calc_clips_normal(2);
let charactersDmg = []

// 卢 无工/狼末 buff
charactersDmg.push(getDMG([charaters.leize,weapons.wugong,{fixedAtt:311,criticalRate:31.1,dmgRate:58.3,attRate:46.6},normal_clips], (data,second) => {
    // 魔女套 15火伤  每放次e + 7.5    0.15精通增伤
    data.dmgRate += 15;
    data.attRate += 80;
    data.dmgRate += 20;  // q 火增伤
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0.15 }
    let qdmg = getDmgDps(data, 3.67, rea) * q(10) * df(90,90);
    let qdmg2 = getDmgDps(data, 1.08*2) * q(10) * df(90,90);
    let a1dmg = getDmgDps(data, 1.77+1.73) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e1dmg = getDmgDps(data, 1.7, rea) * q(10) * df(90,90);
    let a1dmg_1 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.95+2.65) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e2dmg = getDmgDps({...data,dmgRate:data.dmgRate + 40}, 1.76, rea) * q(10) * df(90,90);
    let a1dmg_2 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.77+1.73) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e3dmg = getDmgDps({...data,dmgRate:data.dmgRate + 40}, 2.32, rea) * q(10) * df(90,90);
    let a1dmg_3 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.95+2.65) * q(10) * df(90,90);
    // 后续普攻  第三段是反应
    let admg = getDmgDps(data, 1.77+1.73+ 1.95 + 1.73 +2.65) * q(10) * df(90,90);
    let a3dmgR = getDmgDps(data,1.77 + 1.95 +2.65, rea) * q(10) * df(90,90);
    let e1dmg_dpwn = getDmgDps(data, 1.7, rea) * q(10) * df(90,90);
    let ret = qdmg + qdmg2 + a1dmg + e1dmg + a1dmg_1 + e2dmg + a1dmg_2 + e3dmg + a1dmg_3 + admg + a3dmgR + e1dmg_dpwn
    return {point:ret, data, second, attack , msg:"狼魔buff"}
}))


// 卢 无工/狼末 有buff
charactersDmg.push(getDMG([charaters.leize,weapons.wugong,{fixedAtt:311,criticalRate:31.1,dmgRate:58.3,attRate:46.6},normal_clips], (data,second) => {
    // 魔女套 15火伤  每放次e + 7.5    0.15精通增伤
    data.dmgRate += 15;
    data.attRate += 40;
    data.dmgRate += 20;  // q 火增伤
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0.15 }
    let qdmg = getDmgDps(data, 3.67, rea) * q(10) * df(90,90);
    let qdmg2 = getDmgDps(data, 1.08*2) * q(10) * df(90,90);
    let a1dmg = getDmgDps(data, 1.77+1.73) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e1dmg = getDmgDps(data, 1.7, rea) * q(10) * df(90,90);
    let a1dmg_1 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.95+2.65) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e2dmg = getDmgDps({...data,dmgRate:data.dmgRate + 40}, 1.76, rea) * q(10) * df(90,90);
    let a1dmg_2 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.77+1.73) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e3dmg = getDmgDps({...data,dmgRate:data.dmgRate + 40}, 2.32, rea) * q(10) * df(90,90);
    let a1dmg_3 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.95+2.65) * q(10) * df(90,90);
    // 后续普攻  第三段是反应
    let admg = getDmgDps(data, 1.77+1.73+ 1.95 + 1.73 +2.65) * q(10) * df(90,90);
    let a3dmgR = getDmgDps(data,1.77 + 1.95 +2.65, rea) * q(10) * df(90,90);
    let e1dmg_dpwn = getDmgDps(data, 1.7, rea) * q(10) * df(90,90);
    let ret = qdmg + qdmg2 + a1dmg + e1dmg + a1dmg_1 + e2dmg + a1dmg_2 + e3dmg + a1dmg_3 + admg + a3dmgR + e1dmg_dpwn
    return {point:ret, data, second, attack , msg:"无工有盾"}
}))

// 卢 无工/狼末 无buff
charactersDmg.push(getDMG([charaters.leize,weapons.wugong,{fixedAtt:311,criticalRate:31.1,dmgRate:58.3,attRate:46.6},normal_clips], (data,second) => {
    // 魔女套 15火伤  每放次e + 7.5    0.15精通增伤
    data.dmgRate += 15;
    data.dmgRate += 20;  // q 火增伤
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0.15 }
    let qdmg = getDmgDps(data, 3.67, rea) * q(10) * df(90,90);
    let qdmg2 = getDmgDps(data, 1.08*2) * q(10) * df(90,90);
    let a1dmg = getDmgDps(data, 1.77+1.73) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e1dmg = getDmgDps(data, 1.7, rea) * q(10) * df(90,90);
    let a1dmg_1 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.95+2.65) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e2dmg = getDmgDps({...data,dmgRate:data.dmgRate + 40}, 1.76, rea) * q(10) * df(90,90);
    let a1dmg_2 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.77+1.73) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e3dmg = getDmgDps({...data,dmgRate:data.dmgRate + 40}, 2.32, rea) * q(10) * df(90,90);
    let a1dmg_3 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.95+2.65) * q(10) * df(90,90);
    // 后续普攻  第三段是反应
    let admg = getDmgDps(data, 1.77+1.73+ 1.95 + 1.73 +2.65) * q(10) * df(90,90);
    let a3dmgR = getDmgDps(data,1.77 + 1.95 +2.65, rea) * q(10) * df(90,90);
    let e1dmg_dpwn = getDmgDps(data, 1.7, rea) * q(10) * df(90,90);
    let ret = qdmg + qdmg2 + a1dmg + e1dmg + a1dmg_1 + e2dmg + a1dmg_2 + e3dmg + a1dmg_3 + admg + a3dmgR + e1dmg_dpwn
    return {point:ret, data, second, attack , msg:"狼末无工"}
}))

// 卢 
charactersDmg.push(getDMG([charaters.leize,weapons.cg,{fixedAtt:311,criticalStrike:62.2,dmgRate:58.3,attRate:46.6},normal_clips2], (data,second) => {
    // 魔女套 15火伤  每放次e + 7.5    0.15精通增伤
    data.dmgRate += 15;
    data.dmgRate += 20;  // q 火增伤
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0.15 }
    let qdmg = getDmgDps(data, 3.67, rea) * q(10) * df(90,90);
    let qdmg2 = getDmgDps(data, 1.08*2) * q(10) * df(90,90);
    let a1dmg = getDmgDps(data, 1.77+1.73) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e1dmg = getDmgDps(data, 1.7, rea) * q(10) * df(90,90);
    let a1dmg_1 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.95+2.65) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e2dmg = getDmgDps({...data,dmgRate:data.dmgRate + 40}, 1.76, rea) * q(10) * df(90,90);
    let a1dmg_2 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.77+1.73) * q(10) * df(90,90);
    data.dmgRate += 7.5;
    let e3dmg = getDmgDps({...data,dmgRate:data.dmgRate + 40}, 2.32, rea) * q(10) * df(90,90);
    let a1dmg_3 = getDmgDps({...data,dmgRate:data.dmgRate + 30}, 1.95+2.65) * q(10) * df(90,90);
    // 后续普攻  第三段是反应
    let admg = getDmgDps(data, 1.77+1.73+ 1.95 + 1.73 +2.65) * q(10) * df(90,90);
    let a3dmgR = getDmgDps(data,1.77 + 1.95 +2.65, rea) * q(10) * df(90,90);
    let e1dmg_dpwn = getDmgDps(data, 1.7, rea) * q(10) * df(90,90);
    let ret = qdmg + qdmg2 + a1dmg + e1dmg + a1dmg_1 + e2dmg + a1dmg_2 + e3dmg + a1dmg_3 + admg + a3dmgR + e1dmg_dpwn
    return {point:ret, data, second, attack}
}))
console.log(charactersDmg.sort((a,b)=>b.point-a.point));



function getDMG(dataarr, getRet){
    let chance = 25;
    let _ret = [];
    for (let index = 0; index <= chance; index++) {
        let criticalStrike = index; 
        for (let index2 = 0; index2 <= chance - index; index2++) {
            let criticalRate = index2;
            for (let index3 = 0; index3 <= chance-index-index2; index3++) {
                let attRate = index3;
                let defenceRate = chance - index - index2 - index3;
                _ret.push({
                    精通: 7.3 * defenceRate,
                    attRate:5.8 * attRate,
                    criticalRate:3.9 * criticalRate,
                    criticalStrike:7.8 * criticalStrike
                });
            }
        }
    }
    _ret = _ret.map(second => {
        let panel = getPanel([...dataarr, second]);
        return  getRet(panel, second)
    })
    _ret.sort((b,a)=> a.point-b.point)
    return _ret[0]
}

function getDmgDps(data, rate=1, rea){
    let criticalRate = data.criticalRate
    if(criticalRate > 100){criticalRate = 100}
    let baseat = data.base * (1 + data.attRate/100) + data.fixedAtt;
    let bdmg = baseat * (1 + data.criticalStrike/100);
    let bdps = (criticalRate * 10 * bdmg + (1000-criticalRate * 10)*baseat)/1000
    let adddmg = bdps * (1 + data.dmgRate/100)
    if(rea){
        let {精通, 系数, 精通增伤} = rea
        let tmp = 1 + 精通增伤 + jt(精通);
        return adddmg * rate * 系数 * tmp
    }
    return adddmg * rate
}

function getPanel(arr){
    let info = {name1:"",name2:""};
    arr.forEach((item, i)=>{
        if(item.name){
            info["name" + (i+1)] = item.name
        }
        for (const key in item) {
            if(key !== "name"){
                if(info[key]){
                    info[key] += item[key]
                } else {
                    info[key] = item[key]
                }
            }
        }
    })
    return info
}

function q (resistance) {
    if(resistance < 0) {
        return 1 - resistance/200
    } else if (resistance >=0 && resistance < 75){
        return 1 - resistance/100
    } else {
        return 1/(1+resistance/100*4)
    }
}

function df(youLv=0, eLv=0, td){
    return (100+youLv)/(100+youLv+(100+eLv)*(td? (100-td)/100 : 1))
}

// 固定攻击力 19  防御力23 生命值299 5.3% 
function calc_clips_normal (n) {
    let clips = [
        {
            精通: 23,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            fixedAtt: 19,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            attRate: 5.8,
            criticalRate:n!=2? 0:3.9,
            criticalStrike:n!=2? 7.8:0
        }
    ]
    let data = {}
    clips.forEach(item => {
        for (const key in item) {
            data[key] = data[key]? (data[key]+item[key]) : item[key]
        }
    })
    return data
}

function jt(k){
    return Math.log(0.99316499 + 0.00209988607 * k + 0.0000001213236971*k*k)
}